﻿using System;
using System.Linq;
using RayDen.Library.Core.Primitives;
using RayDen.Library.Entity.Interface;

namespace RayDen.Library.Data.Imaging {
    [Serializable]
    public class FilmFrame : IFilmFrame {
        private readonly int width, height;
        private RgbSpectrum[] data;
        private float[] weight;

        public int NotZeroPixels {
            get { return this.Data.Count(item => !item.IsBlack()); }
        }

        public FilmFrame(int w, int h) {
            data = new RgbSpectrum[w*h];
            weight = new float[w*h];
            width = w;
            height = h;
        }

        public FilmFrame(int w, int h, RgbSpectrum[] d) {
            data = d;
            weight = Enumerable.Repeat(1f, w*h).ToArray();
            width = w;
            height = h;
        }
        #region IFilmFrame Members

        public int Width {
            get { return width; }
        }

        public int Height {
            get { return height; }
        }

        public RgbSpectrum[] Data {
            get { return data; }
            set { data = value; }
        }

        public float[] Weight {
            get { return weight; }
        }

        #endregion

        public int Offset(int x, int y) {
            return width*y + x;
        }
    }
}
